package com.gxa.insurance.service.impl;

import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.exception.ExceptionCode;
import com.gxa.insurance.mapper.PermissionMapper;
import com.gxa.insurance.pojo.Permission;
import com.gxa.insurance.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wang li sha
 * @date 2022-06-06 16:33
 */
@Service("PermissionService")
@Transactional(rollbackFor = Throwable.class)
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public List<Permission> selectAll() throws Exception {
        List<Permission> permissions = permissionMapper.selectAll();
        if (permissions.size() == 0) {
            throw new BusinessException(ExceptionCode.PERMISSION_IS_EMPTY);
        }
        return permissions;
    }

    @Override
    public List<Permission> selectByRoleId(Integer roleId) throws Exception {
        List<Permission> permissions = permissionMapper.selectByRoleId(roleId);
        if (permissions.size() == 0) {
            throw new BusinessException(ExceptionCode.PERMISSION_IS_EMPTY);
        }
        return permissions;
    }
}
